﻿using System;
using K9Nano.Caching;
using Microsoft.Extensions.Configuration;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class RedisCacheExtensions
    {
        public static IServiceCollection AddK9NanoRedisCache(this IServiceCollection service, Action<CSRedisOption> setupAction)
        {
            var option = new CSRedisOption();
            setupAction(option);
            var csredis = new CSRedis.CSRedisClient(option.Connection, option.Sentinels, option.ReadOnly);
            RedisHelper.Initialization(csredis);
            service.AddSingleton<ICache, DefaultCSRedisCache>();
            return service;
        }

        public static IServiceCollection AddK9NanoRedisCache(this IServiceCollection service,IConfiguration configuration)
        {
            return AddK9NanoRedisCache(service, configuration.Bind);
        }
    }
}
